import 'package:data/repository/banner/banner_repository.dart';
import 'package:domain/mapper/banner_domain_model_mapper.dart';
import 'package:domain/model/banner_domain_model.dart';
import 'package:flutter/foundation.dart';
import 'package:util/result/catching.dart';
import 'package:util/result/result_extension.dart';

abstract class BannerUseCase {
  Future<List<BannerDomainModel>> fetchBanners();
}

class BannerUseCaseImpl implements BannerUseCase {
  final BannerRepository _repo;
  BannerUseCaseImpl({required BannerRepository repo}) : _repo = repo;

  @override
  Future<List<BannerDomainModel>> fetchBanners() async {
    final result = await runCatchingAsync(
      () async => await _repo.fetchBanners(),
    );
    debugPrint(result.toString());
    return result.getOrNull()?.map((resp) => resp.toDomainModel()).toList() ??
        [];
  }
}
